<?php
require_once(dirname(__FILE__).'/config.php');
require_once("../order/kill.php");
$aid = isset($aid) && is_numeric($aid) ? $aid : 0;
$dj = isset($dj) && is_numeric($dj) ? $dj : 0;
session_start();
if(!$cfg_ml->IsLogin())
	{
		include_once(dirname(__FILE__)."/templets/index-notlogin.htm");
	}

if($_SESSION["ok_pay_mb"]==$aid.$cfg_ml->M_LoginID)
{
	ShowMsg("请不要重复刷新","-1");
	exit();
}
if($aid=='0')
{
	ShowMsg("参数错误","-1");
	exit();
}

$ro=$dsql->getone("select jiage,title,pay,id from #@__order where aid='$aid'");
if(!$ro)
{
	ShowMsg("订单不存在","-1");
	exit();
}
if($ro['pay']=='1')
{
	ShowMsg("该订单已经扣款成功了，请不要重复操作","-1");
	exit();
}


if($dopost=='')
{
	

	    /* 得到抵用券 */
		$alipay_dyq= alipay_dyq($cfg_ml->M_ID);
		
	
	 
     //$sql = "select * from #@__member where mid='".$cfg_ml->M_ID."'";
     //$dsql->SetQuery($sql);
     //$dsql->Execute();
     //$row = $dsql->GetArray();
        $dpl = new DedeTemplate();
		$tpl = dirname(__FILE__)."/templets/alipay.htm";
		$dpl->LoadTemplate($tpl);
		$dpl->display();
		
}
/*------------------------
function __Save()
------------------------*/
if($dopost=='save')
{
	
$ojiage=$jiage_;
$ojiage = isset($ojiage) && is_numeric($ojiage) ? $ojiage : 0;


	   $rom=$dsql->getone("select money from #@__member where mb='".$cfg_ml->M_LoginID."' and mid='".$cfg_ml->M_ID."'");
	   $money=$rom['money'];
	   $money = isset($money) && is_numeric($money) ? $money : 12;

	   
if(!$rom or $money=='12' or $ojiage<='0')
{
	ShowMsg("严重错误，请联系管理员","alipay",'',"5000");
	exit();
}


if($money<$ojiage) //检测余额
{
ShowMsg("您账号余额不足，请在线充值","/users/edit_money.php",'','5000');
exit();	
}
else
{
	
	//扣款
		$queryk = "Update `#@__member` set money=money-{$ojiage} where  mb='".$cfg_ml->M_LoginID."' and mid='".$cfg_ml->M_ID."'";
	   if(!$dsql->ExecuteNoneQuery($queryk))
		{
			$gerr = $dsql->GetError();
			ShowMsg("扣款失败，请联系管理员","-1");
			exit();	
		}
	
	
	//更改抵用券的状态
		$queryk = "Update `#@__member_pms` set isadmin=1 where  id='$pid'";
	   if(!$dsql->ExecuteNoneQuery($queryk))
		{
			$gerr = $dsql->GetError();
			ShowMsg("扣款失败，请联系管理员","-1");
			exit();	
		}
	
	
	
	//更改订单状态
	 $queryz = "Update `#@__order` set pay='1' where aid='$aid'";
	   if(!$dsql->ExecuteNoneQuery($queryz))
		{
			$gerr = $dsql->GetError();
			ShowMsg("扣款成功，但是更改订单状态失败，请联系管理员","-1");
			exit();	
		}
	
	
	// 推送事件
	//推送事件
		$time=time();
		$ip=getip();
		$inQuery2 = "INSERT INTO `#@__order_zt` (`jiage` ,`mb` ,`title` ,`time`, `ip`, `pay`,`mid`,`xltitle`)
	   VALUES ('$ojiage','".$cfg_ml->M_LoginID."','扣款','$time','$ip','','$aid','".$ro[title]."'); ";
	   if(!$dsql->ExecuteNoneQuery($inQuery2))
		{
			$gerr = $dsql->GetError();
			ShowMsg("扣款成功，但是写入数据库失败，请联系管理员","javascript:;");
			exit();	
		}
	
	   $_SESSION["ok_pay_mb"]=$aid.$cfg_ml->M_LoginID; 
	   
	   
	   
	    $makkkk=$dsql->getone("select mb_4,mb_5 from #@__mb where aid='0'");
		if($makkkk['mb_4']=='1')
		{ // 发送短信
		$alipyf=alipyf($aid,$buyid);
		}	
		if($makkkk['mb_5']=='1')
		{ // 发送短信
		$adminzf=adminzf($aid,$buyid);
		}	
	   
	   ShowMsg("恭喜您，扣款成功，系统已通知管理员","/order/xlsearch.php");
		exit();	
	
}

	
		
		
}
?>